//DatCQ Chon in giay phep theo dinh dang 20/10/2008
function btn_rad_onclick(p_rad_obj,p_hdn_obj){
	p_hdn_obj.value = p_rad_obj.value;
}
//End DatCQ Chon in giay phep theo dinh dang 20/10/2008

function refuse_onclick(rad_obj,hdn_obj){
	hdn_obj.value = rad_obj.value;
	//if (rad_obj.value == "LD_PHONG_TUCHOI" || rad_obj.value == "LD_PHONG_TRALAI" || rad_obj.value == "LD_COQUAN_TUCHOI" ){
	if (rad_obj.value == "LD_PHONG_TUCHOI" || rad_obj.value == "LD_COQUAN_TUCHOI" || rad_obj.value =='RUT_HO_SO'){
		document.all.tr_reason.style.display='block';
		if(rad_obj.value =='RUT_HO_SO'){
			document.forms[0].hdn_revoke.value = true;
			document.all.td_reason_revoke.style.display='block';			
			document.all.td_reason.style.display='none';			
		}
	}else{
		document.forms[0].txt_reason.value = "";
		document.forms[0].hdn_revoke.value = false;
		document.all.tr_reason.style.display='none';
		document.all.td_reason_revoke.style.display='none';
		document.all.td_reason.style.display='block';
	}
	//alert (document.forms[0].hdn_revoke.value);
}
function refuse_onclick_KQTL(rad_obj,hdn_obj){
	hdn_obj.value = rad_obj.value;
	//if (rad_obj.value == "LD_PHONG_TUCHOI" || rad_obj.value == "LD_PHONG_TRALAI" || rad_obj.value == "LD_COQUAN_TUCHOI" ){
	if (rad_obj.value == "LD_PHONG_TUCHOI" || rad_obj.value == "LD_COQUAN_TUCHOI"){
		document.all.tr_reason.style.display='block';
	}else{
		document.forms[0].txt_reason.value = "";
		document.all.tr_reason.style.display='none';
	}
	//alert (document.forms[0].hdn_revoke.value);
}
function refuse_onclick_leav(rad_obj,hdn_obj){
	hdn_obj.value = rad_obj.value;
	//if (rad_obj.value == "LD_PHONG_TUCHOI" || rad_obj.value == "LD_PHONG_TRALAI" || rad_obj.value == "LD_COQUAN_TUCHOI" ){
	if (rad_obj.value =='LD_PHONG_TRALAI_THUE' ||rad_obj.value =='LD_PHONG_TRALAI_PHAT' || rad_obj.value=='TRA_LAI_HOSO' || rad_obj.value =='LD_PHONG_TRALAI_NO_PHAT'){
		document.all.tr_reason.style.display='block';
	}else{
		document.forms[0].txt_reason.value = "";
		document.all.tr_reason.style.display='none';
	}
}
function refuse_onclick_leav22(rad_obj){
	if (rad_obj.value =='LD_PHONG_TRALAI_THUE' ||rad_obj.value =='LD_PHONG_TRALAI_PHAT' || rad_obj.value=='TRA_LAI_HOSO' ||rad_obj.value=='LD_PHONG_TRALAI_NO_PHAT'){
		//document.getElementById('tr_leaders1000').display='none';
		document.all.tr_leaders.style.display='none';
		document.all.tr_reason.style.display='block';
	}else{
		document.all.tr_leaders.style.display='block';
		document.forms[0].txt_reason.value = "";
		document.all.tr_reason.style.display='none';
	}
}
function rad_onclick(rad_obj,hdn_obj){
	var f = document.forms[0],e,v_element;
	for (i=0;i<f.length;i++){
		e=f.elements[i];
		v_element = e.name;
		if(v_element == rad_obj.value){
			document.getElementById("worktype").innerHTML=e.value;
		}
	}	
	if (rad_obj.value!=""){ 
		var url="dsp_all_attach_file_by_one_worktype.php?v_worktype_code=" + rad_obj.value;
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.open("GET", url , true);
		xmlHttp.send(null);
	}else{ 
		document.getElementById("txtHint").innerHTML="";
	}	
	if(rad_obj.value == 'XAC_NHAN_HO_SO'){
		document.forms[0].txt_result.value = "Đã nhận đủ hồ sơ.";
	}else{
		document.forms[0].txt_result.value = "";
	}
	hdn_obj.value = rad_obj.value;
}
function Update_record_status(p_fuseaction){
	if (document.forms[0].hdn_work.value == ''){
		alert('Bạn phải xác định kết quả thụ lý.');
		return;
	}
	btn_save_onclick(p_fuseaction);
}
//NgocNTM
function Update_record_status_dispute(p_fuseaction){
	if (document.forms[0].hdn_work.value == ''){
		alert('Bạn phải xác định trạng thái hồ sơ trước khi cập nhật.');
		return;
	}
	btn_save_onclick(p_fuseaction);
}
//Leav 
function rad_onclick_leav(rad_obj,hdn_obj){
	hdn_obj.value = rad_obj.value;
}
//Leav_end
//Leav_update:25/06/08_begin
function rad_onclick_leav_result(rad_obj,result_obj){
	if(rad_obj.value=='TL_RTB_THUE'){
		result_obj.value='Cán bộ thụ lý trình ký thông báo thuế';
	}else if(rad_obj.value=='TL_RTB_PHAT'){
		result_obj.value='Cán bộ thụ lý trình ký thông báo phạt';
		}else result_obj.value='Cán bộ thụ lý trình ký không thông báo phạt';

}
//NgocNTM
function rad_onclick_dispute_result(rad_obj,result_obj){
	alert("dddd");
	if(rad_obj.value=='TRANH_CHAP'){
		result_obj.value='TRANH_CHAP';
	}else{
		result_obj.value='HET_TRANH_CHAP';
		}
	alert(result_obj.value);return;
}
//Leav_update:25/06/08_end
//Leav_end
function btn_query_onclick(){
	v_current_url = "index.php";
	v_record_id = document.forms[0].hdn_record_id.value;
	v_fuseaction = document.forms[0].fuseaction.value;
	v_recordtype_filter = document.forms[0].hdn_recordtype_filter.value;
	v_current_url = v_current_url + "?fuseaction=" + v_fuseaction + "&hdn_record_id=" + v_record_id + "&hdn_recordtype_filter=" + v_recordtype_filter + "&hdn_query_data=1"
	//alert (v_current_url); 
	window.location = v_current_url;
}
//Vunh added for query data for multilicense
function btn_query_onclick_multilicense(hdn_record_id){
	v_current_url = "index.php";
	v_fuseaction = document.forms[0].fuseaction.value;
	v_recordtype_filter = document.forms[0].hdn_recordtype_filter.value;
	v_record_id_list = document.forms[0].hdn_record_id_list.value;
	v_current_url = v_current_url + "?fuseaction=" + v_fuseaction +  "&hdn_record_id_list=" + v_record_id_list + "&hdn_record_id=" + hdn_record_id + "&hdn_recordtype_filter=" + v_recordtype_filter + "&hdn_query_data=1"
	//alert (v_current_url); 
	window.location = v_current_url;
}
function btn_approve_handler_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Bạn chưa chọn hồ sơ.");
	}	
	else{
		document.forms[0].fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		//var x =  document.f_dsp_all_record_approved.sel_recordtype;
		//document.f_dsp_all_record_approved.value = x.options[x.selectedIndex].text
		document.forms[0].submit(); 
	}	
}
function btn_approving_handler_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Bạn chưa chọn hồ sơ.");
	}	
	else{
		document.forms[0].fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		//var x =  document.f_dsp_all_record_for_approving.sel_recordtype;
		//document.f_dsp_all_record_for_approving.value = x.options[x.selectedIndex].text
		document.forms[0].submit(); 
	}	
}

function show_handler_onclick(p_goto_url,p_fuseaction)
{ 	
	v_url = '';
	//v_url = _DSP_MODAL_DIALOG_URL_PATH;
	v_url = v_url + "?goto_url=" + p_goto_url + "&fuseaction=" + p_fuseaction ;
	v_url = v_url + "&modal_dialog_mode=1" + "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=280pt;dialogTop=80pt;status=no;scroll=no;");
	if (!sRtn) 
		sRtn = document.forms[0].txt_handler_name.value;
	document.forms[0].txt_handler_name.value = sRtn;

}
function Get_handler(v_handler_name){
	window.returnValue = v_handler_name;
	window.close();
}

function show_dialog_all_item_onclick(p_goto_url,p_fuseaction, p_text_name_obj, p_text_code_obj, p_hdn_obj, p_hdn_unit_id){
	if (p_hdn_unit_id == ''){
	 alert ('Bạn phải xác định phòng thụ lý hồ sơ.'); 
	 return;
	}
	//alert(p_hdn_unit_id);
	v_url =  p_goto_url + "?hdn_handle_agency_id="+p_hdn_unit_id + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" + "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=280pt;dialogTop=80pt;status=no;scroll=no;");
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[0];
	p_text_code_obj.value = arr_value[1];		
	p_text_name_obj.value = arr_value[2];
}
function btn_save_sharing_record_onclick(p_fuseaction){
	if (verify(document.forms[0])){
		document.forms[0].fuseaction.value = p_fuseaction;
		document.forms[0].submit();
	}
}
function re_display_list_handler(){
	v_obj = document.all.tr_handler_name;
	v_check_obj = document.all.chk_handler_list_id;
	primary_handler_id = document.forms[0].hdn_primary_handler_id.value;
	if (v_obj.length>1){
		for(i=0;i<v_obj.length;i++){		
			if (v_obj[i].value == primary_handler_id){
				v_check_obj[i].checked=false;
				v_obj[i].style.display = 'none';
			}
			else
				v_obj[i].style.display = 'block';
		}
	}else{
		if (v_obj.value == primary_handler_id){
			v_check_obj.checked=false;
			v_obj.style.display = 'none';
		}
	}
}
function btn_print_license_onclick(p_goto_url,p_item_id,p_type,p_fuseaction) {
	v_url = p_goto_url + "?hdn_record_id=" + p_item_id + "&hdn_recordtype_filter=" + p_type +"&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
	v_url = v_url+ "&" + randomizeNumber();
	//sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=200pt;dialogTop=80pt;status=no;scroll=no;");
	goto_url(v_url,3);
}
//ham nay dc dung khi in phieu trinh ky
function show_window_to_print_submit(p_goto_url,p_checkbox_obj,p_type,p_fuseaction) {
	var list = checkbox_value_to_list(p_checkbox_obj,",");
	if (list) {   //Kiem tra xem co ho so nao duoc chon hay khong?

			v_url = p_goto_url + "?hdn_record_id_list=" + list+ "&hdn_recordtype_filter=" + p_type +"&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
			v_url = v_url+ "&" + randomizeNumber();
			//sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=200pt;dialogTop=80pt;status=no;scroll=no;");
			goto_url(v_url,3);
	} else {
		alert("Bạn chưa chọn hồ sơ.");
		return;		
	}
}
////////////////////
function set_value_for_obj(obj,set_value){
	obj.value = set_value;
}
////////////////////
function convert_string_to_array_hienmt(str_array,a_num)
{
	var i = 0;
	var j = 0;
	var a_array = new Array(a_num);
	var s_tam = '';
	for(i;i<str_array.length;i++)
	{	
		if(str_array.substr(i,1)==',')
		{
			a_array[j] = s_tam;
			j++;
			s_tam = '';
		}else
		{
			s_tam += str_array.substr(i,1);
		}
	}
	//Phan tu cuoi cung khong co dau ","
	a_array[j] = s_tam;
	return a_array;
}
	//begin Kienlt 22/10/2008 khi click nut cap nhap thi nut cap nhap bi disabled
function check_worktype(){
	var v_worktype= document.getElementById('hdn_work').value;
	if(v_worktype!='' || v_worktype==null){
		return true;
		}
	}
	//End Kienlt 22/10/2008 khi click nut cap nhap thi nut cap nhap bi disabled
function test_status_update(obj_status,obj_value,v_num){
	//alert(obj_status.value +"/"+);
	var v_len = obj_status.length;
	
	var v_array = new Array(v_len);
	v_array = convert_string_to_array_hienmt(v_num,v_len);
	/*
	if(v_len <= v_num){
		v_num = v_num - 1;
	}*/
	var v_status = false;
	//kiem tra radio dang check co nam trong mang hay khong.
	if(v_num!='')
		for(var i = 0; i < v_len; i++) {
		//	v_status = obj_status[i].checked;
			if(obj_status[i].checked)
			{
				for(var j = 0; j < v_len; j++)
				{
					if(v_array[j]==i)
						v_status = true;
				}
				var obj_name = obj_status[i].value;
			}
		}
	//End kiem tra============
	var v_content_refuse = obj_value.value;
	//alert(v_status); return false;
	//alert ( obj_name); return false;
	//alert((isblank(v_content_refuse));
	if((v_status) && ((isblank(v_content_refuse) || (v_content_refuse==""))) && obj_name != 'LD_PHONG_TRALAI'){
		if(obj_name == 'RUT_HO_SO')
			alert('Bạn phải xác định lý do công dân rút hồ sơ.');
		else
			alert('Bạn phải xác định lý do từ chối.');
		obj_value.focus();
		return false;
	}
	return true;
}

//*********************NgocNTM******************************
function test_status_update_dispute(obj_status,obj_value,v_num){
	var v_len = obj_status.length;
	var v_array = new Array(v_len);
	v_array = convert_string_to_array_hienmt(v_num,v_len);
	/*
	if(v_len <= v_num){
		v_num = v_num - 1;
	}*/
	var v_status = false;
	//kiem tra radio dang check co nam trong mang hay khong.
	if(v_num!='')
		for(var i = 0; i < v_len; i++) {
		//	v_status = obj_status[i].checked;
			if(obj_status[i].checked)
			{
				for(var j = 0; j < v_len; j++)
				{
					if(v_array[j]==i)
						v_status = true;
				}
			}
		}
	//End kiem tra============
	
	return true;
}
//**********************************************************
function btn_save_onclick(p_fuseaction){
	if (_MODAL_DIALOG_MODE==1)
		document.forms[0].action = "index.php?modal_dialog_mode=1";
	else
		document.forms[0].action = "index.php";

	if (verify(document.forms[0])){
		document.forms[0].fuseaction.value = p_fuseaction;
		document.forms[0].submit();
	}	
}

/*

Nguoi viet: Vu Manh Hung
Y nghia:
	Ham nay kien tra truong hop khi NSD chon ngay cap nhat tien do giai quyet la ngay qua khu.
	Tham so:
	v_list_recordtype: Danh sach ma ho so se khong duoc phep cap nhat ngay giai quyet la ngay qua khu?
	v_current_date_value: Nhan gia tri cua ngay hien thoi cua he thong
	obj_date_process: doi tuong textbox luu ngay ma NSD nhap vao
	Vi Du:
	Voi TTHC cap giay cung nhan quyen su dung dat. Chi cho phep NSD cap nhat vao ngay tuong lai
	btn_save_process_onclick('004','05/02/2007','02/02/2007')
	btn_save_process_onclick('001,003,004','05/02/2007','06/02/2007')
*/
function btn_save_process_onclick(v_list_recordtype, v_current_date_value, obj_date_process){
	var v_process_date_value = obj_date_process.value;
	var arr_recordtype = v_list_recordtype.split(",");
	var v_status = 1;
	v_count = arr_recordtype.length;
	for(v_index = 0;v_index<v_count;v_index++){
		if(arr_recordtype[v_index] == '004'){
			if(date_compare(v_current_date_value,v_process_date_value)<0){
				v_status = 0;
				alert('Ngày cập nhật tiến đọ giải quyết không thể trước ngày hiện tại. ('+ v_current_date_value +').');
				obj_date_process.focus();
				return 0;
			}
			break;
		}
	}
	if(v_status == 1){
		btn_save_onclick('UPDATE_RECORD_WORK');
	}
}
//KienLT:Ham nay dung de update tien do cua nhieu ho so
function btn_save_list_check_onclick(v_list_recordtype, v_current_date_value, obj_date_process){
	//alert('test----------100');
	var v_process_date_value = obj_date_process.value;
	var arr_recordtype = v_list_recordtype.split(",");
	var v_status = 1;
	v_count = arr_recordtype.length;
	for(v_index = 0;v_index<v_count;v_index++){
		if(arr_recordtype[v_index] == '004'){
			if(date_compare(v_current_date_value,v_process_date_value)<0){
				v_status = 0;
				alert('Cap nhap tien do giai quyet nhieu ho so. ('+ v_current_date_value +').');
				obj_date_process.focus();
				return 0;
			}
			break;
		}
	}
	if(v_status == 1){
		
		btn_save_onclick('UPDATE_RECORD_LIST_CHECK');
	}
}
//end KienLT:Ham nay dung de update tien do cua nhieu ho so
//Leav:Ham nay dung de update table thong bao thue cua CAN BO THU LY
function btn_save_thue_onclick(v_list_recordtype, v_current_date_value, obj_date_process){
	var v_process_date_value = obj_date_process.value;
	var arr_recordtype = v_list_recordtype.split(",");
	var v_status = 1;
	v_count = arr_recordtype.length;
	for(v_index = 0;v_index<v_count;v_index++){
		if(arr_recordtype[v_index] == '004'){
			if(date_compare(v_current_date_value,v_process_date_value)<0){
				v_status = 0;
				alert('Ngày cập nhật tiến đọ giải quyết không thể trước ngày hiện tại. ('+ v_current_date_value +').');
				obj_date_process.focus();
				return 0;
			}
			break;
		}
	}
	if(v_status == 1){
		
		btn_save_onclick('UPDATE_RECORD_NOTIFY_TAX');
	}
}
//CAN BO TN THONG BAO THUE
function btn_save_tn_thue_onclick(v_list_recordtype, v_current_date_value, obj_date_process){
	var v_process_date_value = obj_date_process.value;
	var arr_recordtype = v_list_recordtype.split(",");
	var v_status = 1;
	v_count = arr_recordtype.length;
	for(v_index = 0;v_index<v_count;v_index++){
		if(arr_recordtype[v_index] == '004'){
			if(date_compare(v_current_date_value,v_process_date_value)<0){
				v_status = 0;
				alert('Ngày cập nhật tiến đọ giải quyết không thể trước ngày hiện tại. ('+ v_current_date_value +').');
				obj_date_process.focus();
				return 0;
			}
			break;
		}
	}
	if(v_status == 1){
		btn_save_onclick('UPDATE_RECORD_NOTIFY_TAX_TN');
	}
}
//Leav_end

//Dat bo sung de cap nhat danh sach tai lieu kem theo de trinh ky 05/06/2008
function save_hidden_multiple_list(p_chk_obj,the_separator){
	var ret = "";
	try{
		if (!p_chk_obj.length){
			if (p_chk_obj.checked){
				ret=p_chk_obj.value;
				eval('document.forms(0).'+p_chk_obj.xml_tag_in_db_name+'.value="'+ret+'"');
			}
		}else{	
			current_chk_obj = p_chk_obj[0].xml_tag_in_db_name;
			for(i=0;i<p_chk_obj.length;i++){
				next_chk_obj = p_chk_obj[i].xml_tag_in_db_name;	
				//alert(next_chk_obj);
				if (current_chk_obj != next_chk_obj){  //Neu het danh sach thi gan vao gia tri cua danh sach
					eval('document.forms(0).'+current_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				if (p_chk_obj[i].checked){
					ret=list_append(ret,p_chk_obj[i].value,the_separator);					
				}
				if (i==p_chk_obj.length-1){ //Cuoi gan gia tri vao danh sach
					eval('document.forms(0).'+next_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				current_chk_obj = next_chk_obj;
			}
			
		}	
	}catch(e){;}
}

function save_list_onclick(f,hdn_obj_tag,hdn_obj_value){
	var list_tag = "";
	var list_value = "";
	var v_temp = "";
	var v_value = "";
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		if (e.value==""||e.value==null){
			v_value=" ";
		}else{
			v_value=e.value;
		}
		
		if (e.xml_tag_in_db &&(e.type!='radio' && e.type!='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			list_value = list_append(list_value,v_value,_SUB_LIST_DELIMITOR);
		}
		
		if (e.xml_tag_in_db &&(e.type=='radio' || e.type=='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			if (e.checked==true){
				v_temp="true";
			}else{
				v_temp="false";
			}
			list_value = list_append(list_value,v_temp,_SUB_LIST_DELIMITOR);
			
		}
		//alert (e.xml_tag_in_db+"\n"+list_tag+"\n"+list_value);
	}

	if (hdn_obj_tag.value!=null && hdn_obj_value.value!=null){
		hdn_obj_tag.value = list_tag;
		hdn_obj_value.value = list_value;
	}

}
//End: Cap nhat danh sach tai lieu kem theo de trinh ky

//DatCQ Bo sung de cap nhat noi dung giay phep nhieu ho so 30/10/2008
var xmlHttp_GP;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp_GP = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp_GP = new XMLHttpRequest();
	}
}

function update_license_record(hdn_record_id,hdn_obj_tag,hdn_obj_value){
	//alert(hdn_record_id.value+"\n"+hdn_obj_tag.value+"\n"+hdn_obj_value.value);	
	if(hdn_record_id.value!=''&&hdn_obj_tag.value!=''&&hdn_obj_value.value!=''){
		
		createXMLHttpRequest();
		xmlHttp_GP.onreadystatechange = handleStateChange;
				
		try {
			xmlHttp_GP.open("post", "act_update_multiple_license_datcq.php?hdn_record_id="+hdn_record_id.value+"&hdn_list_xml_tag="+hdn_obj_tag.value+"&hdn_list_xml_value="+encodeURI(hdn_obj_value.value), true);				
			xmlHttp_GP.send(false);		
		} catch(err) {
			alert(err.message);
		}
	}else
		alert("Phải có Mã số hồ sơ !");
	
}

function handleStateChange() {
	if(xmlHttp_GP.readyState == 4) {
		if(xmlHttp_GP.status == 200) {
			//alert(xmlHttp_GP.responseText);
			var responseText = xmlHttp_GP.responseText;
			if(responseText != 0)
				alert("Cập nhật thành công hồ sơ của " + responseText);
			else
				alert("Cập nhật không thành công !");
		}
	}
}
//DatCQ Bo sung de cap nhat noi dung giay phep nhieu ho so 30/10/2008
